package com.hrzyit.whistle.cases.presenter

import com.hrzyit.base.ext.execute
import com.hrzyit.base.presenter.BasePresenter
import com.hrzyit.base.rx.BaseObserver
import com.hrzyit.whistle.cases.data.bean.*
import com.hrzyit.whistle.cases.presenter.view.CaseInfoView
import com.hrzyit.whistle.cases.service.ICaseCenterService
import com.hrzyit.whistle.cases.service.IUploadService
import javax.inject.Inject

/**
 * 案件详情 Presenter
 * @author YangWei
 * @date 2019/4/8
 */
class CaseInfoPresenter @Inject constructor() : BasePresenter<CaseInfoView>() {

    @Inject
    lateinit var caseCenterService: ICaseCenterService

    @Inject
    lateinit var uploadService: IUploadService

    /**
     * 获取指定案件详情信息
     * @author YangWei
     * @date 2019/4/8
     * @param caseId    案件id
     * @return 指定案件详情信息
     */
    fun getCaseInfoById(caseId: Long) {
        if (!checkNetWork()) {
            return
        }

        // 显示进度框
        mView.showLoading()

        caseCenterService.getCaseInfoById(caseId)
            .execute(object : BaseObserver<CaseDetailInfoEntity>(mView) {
                override fun onNext(t: CaseDetailInfoEntity) {
                    mView.onGetCaseInfoSuccess(t)
                }
            }, lifecycleProvider)
    }

    /**
     * 上传图片
     * @author YangWei
     * @date 2019/3/31
     * @param photo 本地图片文件路径
     * @return Observable<UploadInfo>   FastDfs 文件路径对象 {@link UploadInfo}
     */
    fun uploadPhoto(photo: String) {

        if (!checkNetWork()) {
            return
        }

        // 显示进度框 ??
        mView.showLoading()

        uploadService.uploadPhoto(photo)
            .execute(object : BaseObserver<UploadInfo>(mView) {

                override fun onNext(t: UploadInfo) {
                    mView.onDisposeUploadResult(t)
                }

            }, lifecycleProvider)

    }


    /**
     * 签收或不签收(受理或不受理)指挥中心派发的案件（指挥中心->单位）
     * @author YangWei
     * @date 2019/4/17
     * @param caseSignInVo  @{link CaseSignInVo}
     * @return 成功(true)|失败(false)
     */
    fun signInCaseFromCenter(caseSignInVo: CaseSignInVo) {

        if (!checkNetWork()) {
            return
        }

        // 显示进度框 ??
        mView.showLoading()

        caseCenterService.signInCaseFromCenter(caseSignInVo)
            .execute(object : BaseObserver<Boolean>(mView) {
                override fun onNext(t: Boolean) {
                    mView.onSignInCaseFromCenterResult(t)
                }
            }, lifecycleProvider)
    }
    /**
     * 保存处置结果
     * @author YangWei
     * @date 2019/4/20
     * @param caseSignInVo  @{link CaseSignInVo}
     * @return 成功(true)|失败(false)
     */
    fun saveCaseDisposeResult(saveDisposeCaseInfoVo: SaveDisposeCaseInfoVo) {
        if (!checkNetWork()) {
            return
        }

        // 显示进度框 ??
        mView.showLoading()

        caseCenterService.saveCaseDisposeResult(saveDisposeCaseInfoVo)
            .execute(object : BaseObserver<Boolean>(mView) {
                override fun onNext(t: Boolean) {
                    mView.onGetSaveCaseDisposeResult(t)
                }
            }, lifecycleProvider)
    }

    fun applyCaseClose(caseApplyCloseVo: CaseApplyCloseVo) {
        if (!checkNetWork()) {
            return
        }

        // 显示进度框 ??
        mView.showLoading()

        caseCenterService.applyCaseClose(caseApplyCloseVo)
            .execute(object : BaseObserver<Boolean>(mView) {
                override fun onNext(t: Boolean) {
                    mView.onGetApplyCaseCloseResult(t)
                }
            }, lifecycleProvider)
    }


    /**
     * 批转：响应/不响应单位批转的案件
     * @author YangWei
     * @date 2019/5/08
     * @param caseSignInVo  @{link CaseSignInVo}
     * @return 成功(true)|失败(false)
     */
    fun signInCaseFromDept(caseSignInVo: CaseSignInVo) {

        if (!checkNetWork()) {
            return
        }

        // 显示进度框 ??
        mView.showLoading()

        caseCenterService.signInCaseFromDept(caseSignInVo)
            .execute(object : BaseObserver<Boolean>(mView) {
                override fun onNext(t: Boolean) {
                    mView.onSignInCaseFromDeptResult(t)
                }
            }, lifecycleProvider)
    }
}